/**
 * Created by Administrator on 2017/3/19 0019.
 */
export default {
    removedarrayitem(aar, int){
        let tempindex = -1;
        aar.map((temp, index)=> {
            if (int == temp) {
                tempindex = index;
            }
        });
        if (tempindex != -1) {
            aar.splice(tempindex, 1);
        }
    },
    dateFormat(time){
        let zero=(n)=>{
            return n = n>=0&&n<10 ? "0"+n : n;
        };
        let y = new Date(time).getFullYear();
        let m = new Date(time).getMonth()+1;
        let d = new Date(time).getDate();
        // let h = new Date(time).getHours();
        // let ms = new Date(time).getMinutes();

        // return zero(y)+"-"+zero(m)+"-"+zero(d)+" "+zero(h)+":"+zero(ms);
        return zero(y)+"-"+zero(m)+"-"+zero(d)
    }, numtoChinese(num){
        let mnum = parseFloat(num);
        let strOutput="",strTemp="",strInTemp='';
        let unitArray = new Array("圆万亿","仟佰拾","零壹贰叁肆伍陆柒捌玖");
        let mnumArray = mnum.toString().split('.');
        let integralnum = mnumArray[0];
        let integrallen = integralnum.length;
        let decimalnum = (mnum.toString().indexOf('.')>=0) ? mnumArray[1].substr(0, 2) : '0';
        let decimallen = decimalnum.length;
        let ints = parseInt(integrallen/4);
        let inty = integrallen%4;
        if (ints>3 || (ints==3 && inty>0)) return "超出范围";
        if (inty>0)
        {
            ints++;
            integralnum = "0000".substr(inty)+integralnum;
            integrallen = integralnum.length;
        }
        var i = 0;
        while (i<integrallen)
        {
            let strOutTemp = "";
            strTemp = integralnum.substr(i, 4);
            i += 4;
            for (let j=0; j<4; j++)
            {
                strInTemp = parseInt(strTemp.substr(j, 1));
                strOutTemp += unitArray[2].substr(strInTemp, 1);
                if (strInTemp>0 && j<3) strOutTemp += unitArray[1].substr(j, 1);
            }
            strOutTemp = strOutTemp.replace(/零+$/, "");
            ints--;
            if (strOutTemp!="") strOutTemp += unitArray[0].substr(ints, 1);
            if (strTemp.substr(3,1)=='0') strOutTemp += "零";
            strOutput += strOutTemp;
        }
        strOutput = strOutput.replace(/零+/g, "零").replace(/^零/, "").replace(/零$/, "");
        if (strOutput=="圆") strOutput = "";
        if (decimallen==2)
        {
            strOutput += (decimalnum.charAt(0)!='0') ? unitArray[2].substr(parseInt(decimalnum.charAt(0)), 1)+"角" : "零";
            if (strOutput=="零") strOutput = "";
            strOutput += unitArray[2].substr(parseInt(decimalnum.charAt(1)), 1)+"分";
        }
        else
        {
            if (decimalnum!='0') strOutput += unitArray[2].substr(parseInt(decimalnum), 1)+"角";
            if (strOutput!="") strOutput += "整";
        }
        if (strOutput=="") strOutput = "金额为零";
        return strOutput;
    },
    authorityCheck(module){

        return true;
        var moduleAuthorityMapper = {
            company:2,//企业管理权
            people:6,//用户管理权
            recharge:19,//充值权
            product:10,//产品管理权
            ticking:22,//反馈处理
            manager:12,//人员管理
            role:14,//角色管理
        };

        let moduleAuthorityId = moduleAuthorityMapper[module];
        let pIds = sessionStorage.getItem('pIds').split(",");
        if (pIds != null){
            let length = pIds.length;
            for (var i = 0 ; i <length ; i++){
                if (pIds[i] == moduleAuthorityId){
                    return true;
                }
            }
        }
        return false;
    },
    signedContractStr(url) {
        url = url.split('?')[1]
        let url1 = url.split('&')
        let arr = {}
        url1.forEach(function(v, i, ele){
            return arr[v.split('=')[0]]  = v.split('=')[1]
        })
        return arr.attname
    },
    dateFormat_hms(time){
        let zero=(n)=>{
            return n = n>0&&n<10 ? "0"+n : n;
        };
        let y = new Date(time).getFullYear();
        let m = new Date(time).getMonth() + 1;
        let d = new Date(time).getDate();
        var h = new Date(time).getHours();
        var min = new Date(time).getMinutes();
        if (min == '0') {
            min = '00'
        }
        return zero(y)+"-"+zero(m)+"-"+zero(d)+" "+zero(h)+":"+zero(min)
    }, /*金额千分制*/
    doubleFormat(obj){
        if(!obj){
            return obj;
        }else{
            return parseFloat(obj).toLocaleString();
        }
    },

}